package com.lz.football.module.main.view
{
	import com.common.utils.Reflection;
	import com.liangzhong.manager.SoundManager;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	
	import lz.controls.core.TitleWindow;

	/**
	 *设置面板 
	 * @author lake
	 * 
	 */	
	public class SysSettingPanel extends TitleWindow implements IComponent
	{
		/**
		 * 声音按钮
		 */		
		private var soundOpenBtn 	:SimpleButton;
		private var soundCloseBtn 	:SimpleButton;
		/**
		 * 音乐按钮
		 */		
		private var musicOpenBtn 	:SimpleButton;
		private var musicCloseBtn 	:SimpleButton;
		
		public function SysSettingPanel()
		{
			super();
		}
		/**
		 * 初始化
		 * @param view
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.football.main.SettingSkin");
			if(_symbolSkin == null)
			{
				destroyView();
				return ;
			}
			this.addChild(_symbolSkin);
			_symbolSkin.cacheAsBitmap = true;
			//初始化宽高
			width = _symbolSkin.width;
			height = _symbolSkin.height;
			//初始化UI界面控件
			windowBg = _symbolSkin.windowBg;//背景框
			//设置可拖动
			dragEnabled = true;
			//设置关闭按钮
			setCloseBtn(_symbolSkin.closeBtn);
			soundOpenBtn 		= _symbolSkin.soundOpenBtn;
			soundCloseBtn 		= _symbolSkin.soundCloseBtn;
			musicOpenBtn 		= _symbolSkin.musicOpenBtn;
			musicCloseBtn 		= _symbolSkin.musicCloseBtn;
			_symbolSkin.musicOpenFlag.visible = false;
			_symbolSkin.musicCloseFlag.visible = true;
			_symbolSkin.soundOpenFlag.visible = true;
			_symbolSkin.soundCloseFlag.visible = false;
			SoundManager.getInstance().isMusicOpen = false;
			SoundManager.getInstance().playMusic("com.football.effect.sound.BgMusic_1",true);
			addEvtListener();
		}
		/**
		 * 添加事件
		 * 
		 */		
		public function addEvtListener():void
		{
			soundOpenBtn.addEventListener(MouseEvent.CLICK,clickhandler);
			soundCloseBtn.addEventListener(MouseEvent.CLICK,clickhandler);
			musicOpenBtn.addEventListener(MouseEvent.CLICK,clickhandler);
			musicCloseBtn.addEventListener(MouseEvent.CLICK,clickhandler);
		}
		/**
		 *点击捕获 
		 * @param e
		 * 
		 */		
		private function clickhandler(e :MouseEvent):void
		{
			switch(e.currentTarget)
			{
				case soundOpenBtn://声音
				{
					if(SoundManager.getInstance().isSoundOpen == false)
					{
						SoundManager.getInstance().isSoundOpen = true;
						_symbolSkin.soundOpenFlag.visible = true;
						_symbolSkin.soundCloseFlag.visible = false;
					}
					break;
				}
				case soundCloseBtn://声音
				{
					if(SoundManager.getInstance().isSoundOpen == true)
					{
						SoundManager.getInstance().isSoundOpen = false;
						_symbolSkin.soundOpenFlag.visible = false;
						_symbolSkin.soundCloseFlag.visible = true;
					}
					break;
				}
				case musicOpenBtn://音乐
				{
					if(SoundManager.getInstance().isMusicOpen == false)
					{
						SoundManager.getInstance().isMusicOpen = true;
						_symbolSkin.musicOpenFlag.visible = true;
						_symbolSkin.musicCloseFlag.visible = false;
					}
					break;
				}
				case musicCloseBtn://音乐
				{
					if(SoundManager.getInstance().isMusicOpen == true)
					{
						SoundManager.getInstance().isMusicOpen = false;
						_symbolSkin.musicOpenFlag.visible = false;
						_symbolSkin.musicCloseFlag.visible = true;
					}
					break;
				}
			}
		}
		/**
		 * 删除事件
		 * 
		 */		
		public function removeEvtListener():void
		{
		}
		/**
		 * 
		 * 销毁
		 */		
		public function destroyView():void
		{
			if(this.parent)
			{
				this.parent.removeChild(this);
			}
		}
	}
}